package thinkingInJava.containers.Test_;

import java.util.LinkedList;

import thinkingInJava.containers.MapEntry;

public class SimpleHashMap4<K,V> extends SimpleHashMap3<K,V> {
	public int size() {
		// Could rely on the inherited implementation, which
		// returns entrySet().size(), but this is faster:
		int sz = 0;
		for(LinkedList<MapEntry<K,V>> bucket : buckets)
			if(bucket != null)
				sz += bucket.size();
		return sz;
	}
	public boolean isEmpty() {
		// Could just say return size() == 0;
		// but this is faster:
		for(LinkedList<MapEntry<K,V>> bucket : buckets)
			if(bucket != null)
				return false;
		return true;
	}
	public boolean containsKey(Object key) {
		// A slight modification of the previous method:
		for(LinkedList<MapEntry<K,V>> bucket : buckets) {
			if(bucket == null) continue;
			for(MapEntry<K,V> mPair : bucket)
				if(mPair.getKey().equals(key))
					return true;
		}
		return false;
	}
}
